home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / compstol / cmpsttl1.lha / CompositeTool / v1.1.dist / HDF / dfi.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-08  |  13.9 KB  |  384 lines

  1. /*-----------------------------------------------------------------------------
  2.  * File:    dfi.h
  3.  * Purpose: HDF internal header file
  4.  * Invokes: stdio.h, sys/file.h
  5.  * Contents: 
  6.  *  Compilation parameters
  7.  *  Machine-dependent definitions
  8.  *  Flexibility definitions: i/o buffering, dynamic memory, structure i/o
  9.  *  Size parameters
  10.  * Remarks: To port to a new system, only dfi.h and Makefile need be modified.
  11.  *          This file is included with user programs, but users do not see it.
  12.  *---------------------------------------------------------------------------*/
  13.  
  14.  
  15. #ifndef DF_MAGICK        /* avoid re-inclusion */
  16.  
  17. #define    DF_MAGICK    "\016\003\023\001" /* ^N^C^S^A */
  18.  
  19. #ifndef FILE
  20. #include <stdio.h>
  21. #endif /*FILE*/
  22.  
  23. /*--------------------------------------------------------------------------*/
  24. /*          Compilation Parameters for Flexibility and Portability          */
  25.  
  26. /* modify this line to allow for machine dependencies */
  27. /*#define    SUN*/
  28. /**IMPORTANT** this is now in the in the makefile */
  29.  
  30. /* Added by MK-C: 02-Apr-90 - don't want to use the macro for the Sun! */
  31. /* -------- */
  32. #if sun
  33. #if i386 || i486
  34. #define SUN386
  35. #elif mc68000 || mc68010 || mc68020 || mc68030 || sparc
  36. #define SUN
  37. #endif
  38. #endif
  39. /* -------- */
  40.  
  41. /* modify this line for buffered/unbuffered i/o */
  42. #define    DF_BUFFIO
  43.  
  44. /* modify this line for dynamic/static memory allocation */
  45. #define    DF_DYNAMIC
  46.  
  47. /* modify this line if structures cannot be read/written as is */
  48. #undef    DF_STRUCTOK        /* leave it this way - hdfsh expects it */
  49.  
  50. /* Current version number */
  51. #define    DFVERSION   3.00
  52.  
  53. /*--------------------------------------------------------------------------*/
  54. /*                              MT/NT constants                             */
  55. /*      four MT nibbles represent int, float, double, uchar                 */
  56. #define    DFMT_SUN        0x1111
  57. #define    DFMT_ALLIANT    0x1111
  58. #define    DFMT_IRIS4      0x1111
  59. #define    DFMT_UNICOS     0x3331
  60. #define    DFMT_CTSS       0x3331
  61. #define    DFMT_VAX        0x2221
  62. #define    DFMT_PC         0x4144    /* note byte swapping ??? */
  63.                 /* check this... */
  64. #define    DFMT_MAC        0x1111
  65. #define DFMT_SUN386    0x1444
  66.  
  67. #define    DFNT_VERSION    1    /* current version of NT info */
  68.  
  69. /* type info codes */
  70. #define    DFNT_UINT       1
  71. #define    DFNT_INT        2
  72. #define    DFNT_UCHAR      3
  73. #define    DFNT_CHAR       4
  74. #define    DFNT_FLOAT      5
  75. #define    DFNT_DOUBLE     6
  76.  
  77. /* class info codes for int */
  78. #define    DFNTI_MBO       1    /* Motorola byte order 2's compl */
  79. #define    DFNTI_VBO       2    /* Vax byte order 2's compl */
  80. #define    DFNTI_IBO       4    /* Intel byte order 2's compl */
  81.  
  82. /* class info codes for float */
  83. #define    DFNTF_IEEE      1    /* IEEE format */
  84. #define    DFNTF_VAX       2    /* Vax format */
  85. #define    DFNTF_CRAY      3    /* Cray format */
  86. #define    DFNTF_PC        4    /* PC floats - flipped IEEE */
  87.  
  88. /* class info codes for char */
  89. #define    DFNTC_BYTE      0    /* bitwise/numeric field */
  90. #define    DFNTC_ASCII     1    /* ASCII */
  91. #define    DFNTC_EBCDIC    5    /* EBCDIC */
  92.  
  93. /* array order */
  94. #define    DFO_FORTRAN     1    /* column major order */
  95. #define    DFO_C           2    /* row major order */
  96.  
  97. char *malloc();
  98.  
  99. /*--------------------------------------------------------------------------*/
  100. /*                      Machine dependencies                                */
  101. #ifdef PC
  102. #ifndef O_RDONLY
  103. #include <fcntl.h>
  104. #define    L_INCR  1
  105. #endif /*O_RDONLY*/
  106. #define    int16 int
  107. #define    uint16 unsigned int
  108. #define    int32 long int
  109. #define    float32 double
  110. #define    DFmovmem(from, to, len) memcpy(to, from, len)
  111. #undef DF_STRUCTOK                  /* structure writing will not work on PC */
  112. #undef DF_BUFFIO                    /* unbuffered i/o is faster */
  113. long longswap();                    /* provided elsewhere */
  114.  
  115.     /* in the next 3 lines, p is recast so right number of bytes passed */
  116.     /* ### Note that all calls modify p.  Need to use temporary ptr */
  117. #define    UINT16READ(p, x) { x = ((*p++) & 255)<<8; x |= (*p++) & 255; }
  118. #define    INT16READ(p, x) { x = (*p++)<<8; x |= (*p++) & 255; }
  119. #define    INT32READ(p, x) { x = (*p++)<<24; x|=((*p++) & 255)<<16;    \
  120.             x|=((*p++) & 255)<<8; x|=(*p++) & 255; }
  121. #define    UINT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  122. #define    INT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  123. #define    INT32WRITE(p, x) { *p++ = (x>>24) & 255; *p++ = (x>>16) & 255;  \
  124.             *p++ = (x>>8) & 255; *p++ = x & 255; }
  125. #define    DF_CREAT(name, prot) creat(name, prot)
  126. #define    DF_MT   DFMT_PC
  127. #endif /*PC*/
  128.  
  129.  
  130. #ifdef UNICOS
  131. #ifndef O_RDONLY
  132. #include <sys/fcntl.h>              /* for unbuffered i/o stuff */
  133. #define    L_INCR  1
  134. #endif /*O_RDONLY*/
  135. #define    int16 int
  136. #define    uint16 int
  137. #define    int32 int
  138. #define    float32 float
  139. #define    DFmovmem(from, to, len) memcpy(to, from, len)
  140. #undef DF_STRUCTOK          /* cannot directly read/write structures */
  141. #define    DF_CAPFNAMES            /* fortran names are in all caps */
  142. #define    UINT16READ(p, x)    { x = ((*p++) & 255)<<8; x |= (*p++) & 255; }
  143. #define    INT16READ(p, x)     { x = (*p++)<<8; x |= (*p++) & 255; }
  144. #define    INT32READ(p, x)     { x = (*p++)<<24; x|=((*p++) & 255)<<16;    \
  145.                                 x|=((*p++) & 255)<<8; x|=(*p++) & 255; }
  146. #define    UINT16WRITE(p, x)   { *p++ = (x>>8) & 255; *p++ = x & 255; }
  147. #define    INT16WRITE(p, x)    { *p++ = (x>>8) & 255; *p++ = x & 255; }
  148. #define    INT32WRITE(p, x)    { *p++ = (x>>24) & 255; *p++ = (x>>16) & 255;   \
  149.                                 *p++ = (x>>8) & 255; *p++ = x & 255; }
  150. #define    DF_CREAT(name, prot) creat(name, prot)
  151. #define    DF_MT   DFMT_UNICOS
  152. #endif /*UNICOS*/
  153.  
  154.  
  155. #ifdef SUN
  156. #if ! defined mc68010 && ! defined mc68020 && ! defined mc68030
  157. #undef DF_STRUCTOK
  158. #endif
  159. #include <sys/file.h>               /* for unbuffered i/o stuff */
  160. #define    int16 short
  161. #define    uint16 unsigned short
  162. #define    int32 long
  163. #define    float32 float
  164. #define    DFmovmem(from, to, len) memcpy(to, from, len)
  165. #ifndef DF_STRUCTOK
  166. #define    UINT16READ(p, x) { x = ((*p++) & 255)<<8; x |= (*p++) & 255; }
  167. #define    INT16READ(p, x) { x = (*p++)<<8; x |= (*p++) & 255; }
  168. #define    INT32READ(p, x) { x = (*p++)<<24; x|=((*p++) & 255)<<16;    \
  169.             x|=((*p++) & 255)<<8; x|=(*p++) & 255; }
  170. #define    UINT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  171. #define    INT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  172. #define    INT32WRITE(p, x) { *p++ = (x>>24) & 255; *p++ = (x>>16) & 255;  \
  173.             *p++ = (x>>8) & 255; *p++ = x & 255; }
  174. #endif /*DF_STRUCTOK*/
  175. #define    DF_CREAT(name, prot) creat(name, prot)
  176. #define    DF_MT   DFMT_SUN
  177. #endif /*SUN*/
  178.  
  179. #ifdef SUN386
  180. #undef DF_STRUCTOK
  181. #include <sys/file.h>               /* for unbuffered i/o stuff */
  182. #define    int16 short
  183. #define    uint16 unsigned short
  184. #define    int32 long
  185. #define    float32 float
  186. #define    DFmovmem(from, to, len) memcpy(to, from, len)
  187. #ifndef DF_STRUCTOK
  188. #define    UINT16READ(p, x) { x = ((*p++) & 255)<<8; x |= (*p++) & 255; }
  189. #define    INT16READ(p, x) { x = (*p++)<<8; x |= (*p++) & 255; }
  190. #define    INT32READ(p, x) { x = (*p++)<<24; x|=((*p++) & 255)<<16;    \
  191.             x|=((*p++) & 255)<<8; x|=(*p++) & 255; }
  192. #define    UINT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  193. #define    INT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  194. #define    INT32WRITE(p, x) { *p++ = (x>>24) & 255; *p++ = (x>>16) & 255;  \
  195.             *p++ = (x>>8) & 255; *p++ = x & 255; }
  196. #endif /*DF_STRUCTOK*/
  197. #define    DF_CREAT(name, prot) creat(name, prot)
  198. #define    DF_MT   DFMT_SUN386
  199. #endif /* SUN386 */
  200.  
  201. #ifdef ALLIANT
  202. #include <sys/file.h>               /* for unbuffered i/o stuff */
  203. #define    int16 short
  204. #define    uint16 unsigned short
  205. #define    int32 long
  206. #define    float32 float
  207. #define    DFmovmem(from, to, len) bcopy(from, to, len)
  208. #ifndef DF_STRUCTOK
  209. #define    UINT16READ(p, x)    { x = ((*p++) & 255)<<8; x |= (*p++) & 255; }
  210. #define    INT16READ(p, x)     { x = (*p++)<<8; x |= (*p++) & 255; }
  211. #define    INT32READ(p, x)     { x = (*p++)<<24; x|=((*p++) & 255)<<16;    \
  212.                                 x|=((*p++) & 255)<<8; x|=(*p++) & 255; }
  213. #define    UINT16WRITE(p, x)   { *p++ = (x>>8) & 255; *p++ = x & 255; }
  214. #define    INT16WRITE(p, x)    { *p++ = (x>>8) & 255; *p++ = x & 255; }
  215. #define    INT32WRITE(p, x)    { *p++ = (x>>24) & 255; *p++ = (x>>16) & 255;   \
  216.                                 *p++ = (x>>8) & 255; *p++ = x & 255; }
  217. #endif /*DF_STRUCTOK*/
  218. #define    DF_CREAT(name, prot) creat(name, prot)
  219. #define    DF_MT   DFMT_ALLIANT
  220. #endif /*ALLIANT*/
  221.  
  222.  
  223. #ifdef IRIS4
  224. #undef DF_STRUCTOK
  225. #include <sys/types.h>
  226. #include <sys/file.h>               /* for unbuffered i/o stuff */
  227. #define    int16 short
  228. #define    uint16 unsigned short
  229. #define    int32 long
  230. #define    float32 float
  231. #define    DFmovmem(from, to, len) bcopy(from, to, len)
  232. #ifndef DF_STRUCTOK
  233. #define    UINT16READ(p, x)    { x = ((*p++) & 255)<<8; x |= (*p++) & 255; }
  234. #define INT16READ(p, x)     { x = (*p++)<<8; x |= (*p++) & 255; }
  235. #define INT32READ(p, x)     { x = (*p++)<<24; x|=((*p++) & 255)<<16;    \
  236.                                 x|=((*p++) & 255)<<8; x|=(*p++) & 255; }
  237. #define UINT16WRITE(p, x)   { *p++ = (x>>8) & 255; *p++ = x & 255; }
  238. #define INT16WRITE(p, x)    { *p++ = (x>>8) & 255; *p++ = x & 255; }
  239. #define INT32WRITE(p, x)    { *p++ = (x>>24) & 255; *p++ = (x>>16) & 255;   \
  240.                                 *p++ = (x>>8) & 255; *p++ = x & 255; }
  241. #endif /*DF_STRUCTOK*/
  242. #define DF_CREAT(name, prot) creat(name, prot)
  243. #define DF_MT   DFMT_IRIS4
  244. #endif /*IRIS4*/
  245.  
  246.  
  247. #ifdef MAC
  248. #undef DF_BUFFIO        /* use unbuffered i/o */
  249. #include <memory.h>             /* malloc stuff for MPW 3.0 */
  250. #include <fcntl.h>              /* unbuffered IO stuff for MPW 3.0 */
  251. #ifdef THINK_C                  /* for LightSpeed C */
  252. #include <unix.h>
  253. #else /*THINK_C                   MPW, possibly others */
  254. #include <Files.h>              /* for unbuffered i/o stuff */
  255. #endif /*THINK_C*/
  256. #define    DF_CAPFNAMES            /* fortran names are in all caps */
  257. #define DF_DYNAMIC        /* use dynamic allocation */
  258. #define int16 short
  259. #define uint16 unsigned short
  260. #define int32 long
  261. #define float32 float
  262. #ifdef THINK_C                   /* LightSpeed C does not have memcpy */
  263. #define DFmovmem(from, to, len) DFImemcopy(from, to, len)
  264. #else /*THINK_C*/
  265. #define DFmovmem(from, to, len) memcpy(to, from, len)
  266. #endif /*THINK_C*/
  267. #define malloc(x)   NewPtr((Size)   (x))    /* don't use malloc on the Mac */
  268. #define free(x)     DisposPtr((Ptr) (x))    /* don't use free on the Nac   */ 
  269. #undef DF_STRUCTOK
  270. #define UINT16READ(p, x) { x = ((*p++) & 255)<<8; x |= (*p++) & 255; }
  271. #define INT16READ(p, x) { x = (*p++)<<8; x |= (*p++) & 255; }
  272. #define INT32READ(p, x) { x = (*p++)<<24; x|=((*p++) & 255)<<16;    \
  273.             x|=((*p++) & 255)<<8; x|=(*p++) & 255; }
  274. #define UINT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  275. #define INT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  276. #define INT32WRITE(p, x) { *p++ = (x>>24) & 255; *p++ = (x>>16) & 255;  \
  277.             *p++ = (x>>8) & 255; *p++ = x & 255; }
  278. #define DF_CREAT(name, prot) open(name, O_WRONLY|O_TRUNC|O_CREAT)
  279. #define DF_MT   DFMT_MAC
  280. #endif /*MAC*/
  281.  
  282. #ifdef VMS
  283. /*#undef DF_BUFFIO should be buff !!!!*/
  284.    /* use only unbuff i/o - buff doesn't work! */
  285. #ifndef DFopen                  /* avoid double includes */
  286. #include "dfivms.h"
  287. #endif /*DFopen*/
  288. #undef DF_STRUCTOK
  289. #define DF_CAPFNAMES            /* fortran names are in all caps */
  290. #include <file.h>               /* for unbuffered i/o stuff */
  291. #define int16 short
  292. #define uint16 unsigned short
  293. #define int32 long
  294. #define float32 float
  295. #define DFmovmem(from, to, len) memcpy(to, from, len)
  296. #ifndef DF_STRUCTOK
  297. #define UINT16READ(p, x) { x = ((*p++) & 255)<<8; x |= (*p++) & 255; }
  298. #define INT16READ(p, x) { x = (*p++)<<8; x |= (*p++) & 255; }
  299. #define INT32READ(p, x) { x = (*p++)<<24; x|=((*p++) & 255)<<16;    \
  300.             x|=((*p++) & 255)<<8; x|=(*p++) & 255; }
  301. #define UINT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  302. #define INT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  303. #define INT32WRITE(p, x) { *p++ = (x>>24) & 255; *p++ = (x>>16) & 255;  \
  304.             *p++ = (x>>8) & 255; *p++ = x & 255; }
  305. #endif /*DF_STRUCTOK*/
  306. #define DF_CREAT(name, prot) creat(name, prot)
  307. #define DF_MT   DFMT_VAX
  308. #endif /*VMS*/
  309.  
  310.  
  311.  
  312. /*--------------------------------------------------------------------------*/
  313. /*                      Flexibility parameters                              */
  314.  
  315. #ifdef DF_BUFFIO            /* set all calls to do buffered I/O */
  316. #define DF_OPEN(x,y) fopen(x,y)
  317. #define DF_CLOSE(x) fclose(x)
  318. #define DF_SEEK(x,y,z) fseek(x,y,z)
  319. #define DF_SKEND(x,y,z) fseek(x,y,z)
  320. #define DF_TELL(x) ftell(x)
  321. #define DF_READ(a,b,c,d) fread(a,b,c,d)
  322. #define DF_WRITE(a,b,c,d) fwrite(a,b,c,d)
  323. #define DF_FLUSH(a) fflush(a)
  324. #ifdef PC
  325. #define DF_RDACCESS "rb"
  326. #define DF_WRACCESS "rb+"
  327. #else /*PC*/
  328. #define DF_RDACCESS "r"
  329. #define DF_WRACCESS "r+"
  330. #endif /*PC*/
  331.  
  332. #else /*DF_BUFFIO         unbuffered i/o */
  333. #define DF_OPEN(x,y) open(x,y)
  334. #define DF_CLOSE(x) close(x)
  335. #define DF_SEEK(x,y,z) lseek(x,y,z)
  336. #define DF_SKEND(x,y,z) lseek(x,-1*y,z)
  337. #define DF_TELL(x) lseek(x,0L,1)
  338. #define DF_READ(a,b,c,d) read(d,a,b*c)
  339. #define DF_WRITE(a,b,c,d) write(d,a,b*c)
  340. #define DF_FLUSH(a)                             /* no need to flush */
  341. #ifdef PC
  342. #define DF_RDACCESS O_RDONLY | O_RAW
  343. #define DF_WRACCESS O_RDWR | O_RAW
  344. #else /*PC*/
  345. #define DF_RDACCESS O_RDONLY
  346. #define DF_WRACCESS O_RDWR
  347. #endif /*PC*/
  348. #endif /*DF_BUFFIO*/
  349.  
  350.  
  351.     /* if not allocating memory dynamically, need buffer for compression */
  352. #ifndef DF_DYNAMIC
  353. #define DF_TBUF
  354. #define DF_TBUFSZ    10000    /* buffer size */
  355. #endif /*DF_DYNAMIC*/
  356.  
  357.     /* if reading/writing structures not ok, need buffer for conversion */
  358. #ifndef DF_TBUF
  359. #ifndef DF_STRUCTOK
  360. #define DF_TBUF
  361. #define DF_TBUFSZ    256    /* buffer size can be smaller */
  362. #endif /*DF_STRUCTOK*/
  363. #endif /*DF_TBUF*/
  364.  
  365.     /* set buffer size */
  366. #ifdef DF_TBUF
  367. #ifndef DFMASTER
  368. extern
  369. #endif /*DFMASTER*/
  370.     char DFtbuf[DF_TBUFSZ];
  371. #endif /*DF_TBUF*/
  372.  
  373. /*--------------------------------------------------------------------------*/
  374. /*                          Size parameters                                 */
  375. #define DF_MAXDFS           32  /* How many DF's can be open at once */
  376. #define DF_DEFAULTDDS       16  /* How many DD's a file has by default */
  377. #define DF_MAXFNLEN         256 /* maximum length of filename parameters */
  378.  
  379. char *strncpy();
  380. char *strcpy();
  381. char *malloc();
  382. char *memcpy();
  383. #endif /*DF_MAGICK*/
  384.